import http from '@/router/axios'

/**
 * [根据用户名登陆]
 * @param  {[type]} username [description]
 * @param  {[type]} password [description]
 * @param  {[type]} code     [description]
 * @return {[type]}          [description]
 */
export const loginByUsername = (username, password, code) => {
	let params = {
		email:username,
		password:password,
		type:'add'
	}
	return new Promise((resolve, reject)=>{
		http.post('/accservice/user/login',params).then(res=>{
			if(res.data.result == 0){
				resolve({data:res.data.data})
			}
		}).catch(res=>{
			reject('error')
		})
	})
}
/**
 * 菜单列表
 * @param  {[type]} parentId [description]
 * @return {[type]}          [description]
 */
export const getMenu = (parentId) => {
	return new Promise((resolve, reject) => {
		http.get('/accservice/user/menus').then(res=>{
			if(res.data.result == 0){
				resolve({data:res.data.data})
			}
		})
	})
}
/**
 * 用户列表
 * @param  {[type]} parentId [description]
 * @return {[type]}          [description]
 */
export const getUsers = (parentId) => {
	return new Promise((resolve, reject) => {
		http.get('/accservice/user/list').then(res=>{
			if(res.data.result == 0){
				resolve({data:res.data.data})
			}
		})
	})
}
/**
 * 角色列表
 * @param  {[type]} parentId [description]
 * @return {[type]}          [description]
 */
export const getRoles = (parentId) => {
	return new Promise((resolve, reject) => {
		http.get('/accservice/role').then(res=>{
			if(res.data.result == 0){
				resolve({data:res.data.data})
			}
		})
	})
}
/**
 * 用户信息
 * @return {[type]} [description]
 */
export const getUserInfo = () => {
    return new Promise((resolve, reject) => {
        // resolve({ data: userInfo });
    })
}
/**
 * 退出系统
 * @return {[type]} [description]
 */
export const logout = () => {
    return new Promise((resolve, reject) => {
        resolve();
    })
}